<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <link rel="icon" type="image/x-icon" href="#"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="icon/iconfont.css">
    <link rel="stylesheet" href="modal.css">
    <script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js">
    </script>
    <title>Apple - 门店库存监控订阅！</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        html,
        body {
            height: 100%;
        }

        input:focus {
            outline: none;
        }

        .form input {
            width: 300px;
            height: 30px;
            font-size: 18px;
            background: none;
            border: none;
            border-bottom: 1px solid #fff;
            color: #fff;
            margin-bottom: 20px;
        }

        .form select {
            width: 300px;
            height: 30px;
            font-size: 18px;
            background: none;
            border: none;
            border-bottom: 1px solid #fff;
            color: #fff;
            margin-bottom: 20px;
        }

        .form input::placeholder {
            color: rgba(255, 255, 255, 0.8);
            font-size: 18px;
            font-family: "neo";
        }

        .confirm {
            height: 0;
            overflow: hidden;
            transition: .25s;
        }

        .btn {
            width: 140px;
            height: 40px;
            border: 1px solid #fff;
            background: none;
            font-size: 20px;
            color: #fff;
            cursor: pointer;
            margin-top: 25px;
            font-family: "neo";
            transition: .25s;
        }

        .btn:hover {
            background: rgba(255, 255, 255, .25);
        }

        #login_wrap {
            width: 980px;
            min-height: 500px;
            border-radius: 10px;
            font-family: "neo";
            overflow: hidden;
            box-shadow: 0px 0px 120px rgba(0, 0, 0, 0.25);
            position: fixed;
            top: 50%;
            right: 50%;
            margin-top: -250px;
            margin-right: -490px;
        }

        #login {
            width: 50%;
            height: 100%;
            min-height: 500px;
            background: linear-gradient(45deg, #9a444e, #e06267);
            position: relative;
            float: right;
        }

        select option {
            color: #25133c
        }

        #login #status {
            width: 140px;
            height: 35px;
            margin: 40px auto;
            color: #fff;
            font-size: 30px;
            font-weight: 600;
            position: relative;
            overflow: hidden;
        }

        #login #status i {
            font-style: normal;
            position: absolute;
            transition: .5s
        }

        #login span {
            text-align: center;
            position: absolute;
            left: 50%;
            margin-left: -150px;
            top: 52%;
            margin-top: -140px;
        }

        #login span a {
            text-decoration: none;
            color: #fff;
            display: block;
            margin-top: 80px;
            font-size: 18px;
        }

        #bg {
            background: linear-gradient(45deg, #211136, #bf5853);
            height: 100%;
        }

        /*绘图*/
        #login_img {
            width: 50%;
            min-height: 500px;
            background: linear-gradient(45deg, #221334, #6c3049);
            float: left;
            position: relative;
        }

        #login_img span {
            position: absolute;
            display: block;
        }

        #login_img .circle {
            width: 200px;
            height: 200px;
            border-radius: 50%;
            background: linear-gradient(45deg, #df5555, #ef907a);
            top: 70px;
            left: 50%;
            margin-left: -100px;
            overflow: hidden;
        }

        #login_img .circle span {
            width: 150px;
            height: 40px;
            border-radius: 50px;
            position: absolute;
        }

        #login_img .circle span:nth-child(1) {
            top: 30px;
            left: -38px;
            background: #c55c59;
        }

        #login_img .circle span:nth-child(2) {
            bottom: 20px;
            right: -35px;
            background: #934555;
        }

        #login_img .star span {
            background: radial-gradient(#fff 10%, #fff 20%, rgba(72, 34, 64, 0));
            border-radius: 50%;
            box-shadow: 0 0 7px #fff;
        }

        #login_img .star span:nth-child(1) {
            width: 15px;
            height: 15px;
            top: 50px;
            left: 30px;
        }

        #login_img .star span:nth-child(2) {
            width: 10px;
            height: 10px;
            left: 360px;
            top: 80px;
        }

        #login_img .star span:nth-child(3) {
            width: 5px;
            height: 5px;
            top: 400px;
            left: 80px;
        }

        #login_img .star span:nth-child(4) {
            width: 8px;
            height: 8px;
            top: 240px;
            left: 60px;
        }

        #login_img .star span:nth-child(5) {
            width: 4px;
            height: 4px;
            top: 20px;
            left: 200px;
        }

        #login_img .star span:nth-child(6) {
            width: 4px;
            height: 4px;
            top: 460px;
            left: 410px;
        }

        #login_img .star span:nth-child(7) {
            width: 6px;
            height: 6px;
            top: 250px;
            left: 350px;
        }

        #login_img .fly_star span {
            width: 90px;
            height: 3px;
            background: -webkit-linear-gradient(left, rgba(255, 255, 255, 0.67), rgba(255, 255, 255, 0));
            background: -o-linear-gradient(left, rgba(255, 255, 255, 0.67), rgba(255, 255, 255, 0));
            background: linear-gradient(to right, rgba(255, 255, 255, 0.67), rgba(255, 255, 255, 0));
            transform: rotate(-45deg);
        }

        #login_img .fly_star span:nth-child(1) {
            top: 60px;
            left: 80px;
        }

        #login_img .fly_star span:nth-child(2) {
            top: 210px;
            left: 332px;
            opacity: 0.6;
        }

        #login_img p {
            text-align: center;
            color: #af4b55;
            font-weight: 600;
            margin-top: 365px;
            font-size: 25px;
        }

        #login_img p i {
            font-style: normal;
            margin-right: 45px;
        }

        #login_img p i:nth-last-child(1) {
            margin-right: 0;
        }

        /*提示*/
        #hint {
            width: 100%;
            line-height: 70px;
            background: linear-gradient(-90deg, #9b494d, #bf5853);
            text-align: center;
            font-size: 25px;
            color: #fff;
            box-shadow: 0 0 20px #733544;
            display: none;
            opacity: 0;
            transition: .5s;
            position: absolute;
            top: 0;
            z-index: 999;
        }

        /* 响应式 */
        @media screen and (max-width: 1000px ) {
            #login_img {
                display: none;
            }

            #login_wrap {
                width: 490px;
                margin-right: -245px;
            }

            #login {
                width: 100%;

            }
        }

        @media screen and (max-width: 560px ) {
            #login_wrap {
                width: 330px;
                margin-right: -165px;
            }

            #login span {
                margin-left: -125px;
            }

            .form input {
                width: 250px;
            }

            .btn {
                width: 113px;
            }
        }

        @media screen and (max-width: 345px ) {
            #login_wrap {
                width: 290px;
                margin-right: -145px;
            }
        }
    </style>
</head>
<body>
<div id="bg">
    <div id="login_wrap">
        <div id="login"><!-- 登录注册切换动画 -->
            <div id="status">
                <i style="top: 0">退订</i>
                <i style="top: 35px">订阅</i>
                <i style="right: 0px">通知</i>
            </div>
            <span>
                    <form action="post">
                        <p class="form"><input type="text" id="email" placeholder="邮箱地址"></p>
                        <p class="form confirm"><select style="opacity:1;" id="city"></select></p>
						<p class="form confirm"><select style="opacity:1;" id="model"></select></p>
                        <input type="button" value="退订" class="btn" onclick="unsubscribe()" style="margin-right: 20px;">
                        <input type="button" value="订阅" class="btn" onclick='subscription()' id="btn">
                    </form>
                    <a id="reward" href="#" style="font-size: 12px;">打赏</a>
                    <a id="explanation" href="#" style="font-size: 14px;margin-top: 35px;">使用说明</a>
                    <a style="margin-top: 35px;" href="https://reserve-prime.apple.com/CN/zh_CN/reserve/A/availability?iUP=N#" target="_blank">进入官网</a>
            </span>
        </div>
        <div id="login_img"><!-- 图片绘制框 -->
            <span class="circle">
                    <span></span>
                    <span></span>
                </span>
            <span class="star">
                    <span></span>
                    <span></span>
                    <span></span>
                    <span></span>
                    <span></span>
                    <span></span>
                    <span></span>
                    <span></span>
                </span>
            <span class="fly_star">
                    <span></span>
                    <span></span>
                </span>
            <p id="title">APPLE</p>
        </div>
    </div>
</div>
</body>
<script>
    var onoff = true//根据此布尔值判断当前为注册状态还是登录状态
    var confirm_0 = document.getElementsByClassName("confirm")[0]
    var confirm_1 = document.getElementsByClassName("confirm")[1]
    var email = document.getElementById("email")
    var city = document.getElementById("city")
    var model = document.getElementById("model")

    $(document).ready(function () {
        //加载城市
        $.ajax({
            //请求方式
            type: "GET",
            //请求的媒体类型
            contentType: "application/json;charset=UTF-8",
            //请求地址
            url: "/getStores",
            //请求成功
            success: function (result) {
                if (result.code === 200) {
                    $.each(result.data, function (index, item) {
                        $("#city").append(  //此处向select中循环绑定数据
                            "<option value=" + item.city + ">" + item.city + "</option>");
                    });
                } else {
                    alert("城市加载失败！")
                }
            },
            //请求失败，包含具体的错误信息
            error: function (e) {
                console.log(e.status);
                console.log(e.responseText);
            }
        });
        //加载型号
        $.ajax({
            //请求方式
            type: "GET",
            //请求的媒体类型
            contentType: "application/json;charset=UTF-8",
            //请求地址
            url: "/getModel",
            //请求成功
            success: function (result) {
                if (result.code === 200) {
                    $.each(result.data, function (index, item) {
                        $("#model").append(  //此处向select中循环绑定数据
                            "<option value=" + item.id + ">" + item.content + "</option>");
                    });
                } else {
                    alert("城市加载失败！")
                }
            },
            //请求失败，包含具体的错误信息
            error: function (e) {
                console.log(e.status);
                console.log(e.responseText);
            }
        });
    });

    //自动居中title
    var name_c = document.getElementById("title")
    var name = name_c.innerHTML.split("")
    name_c.innerHTML = ""
    for (i = 0; i < name.length; i++)
        if (name[i] !== ",")
            name_c.innerHTML += "<i>" + name[i] + "</i>"

    //订阅按钮
    function subscription() {
        let status = document.getElementById("status").getElementsByTagName("i")
        if (onoff) {
            confirm_0.style.height = 51 + "px"
            confirm_1.style.height = 51 + "px"
            status[0].style.top = 35 + "px"
            status[1].style.top = 0
            onoff = !onoff
        } else {
            if (!/^[a-zA-Z0-9_.-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/.test(email.value))
                alert("请检查邮箱地址是否错误！");
            else {
                $.ajax({
                    //请求方式
                    type: "POST",
                    //请求的媒体类型
                    contentType: "application/json;charset=UTF-8",
                    data: JSON.stringify({"email": email.value, "city": city.value, "model": model.value}),
                    dataType: "json",
                    //请求地址
                    url: "/addUser",
                    //请求成功
                    success: function (result) {
                        $("#email").val("");
                        if (result.code === 200) {
                            alert(result.data);
                        } else {
                            alert(result.msg);
                        }
                    },
                    //请求失败，包含具体的错误信息
                    error: function (e) {
                        console.log(e.status);
                        console.log(e.responseText);
                    }
                });
            }
        }
    }

    //退订按钮
    function unsubscribe() {
        if (onoff) {
            if (!/^[a-zA-Z0-9_.-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/.test(email.value))
                alert("请检查邮箱地址是否错误！");
            else {
                $.ajax({
                    //请求方式
                    type: "GET",
                    //请求的媒体类型
                    contentType: "application/json;charset=UTF-8",
                    data: {"email": email.value},
                    dataType: "json",
                    //请求地址
                    url: "/delUser",
                    //请求成功
                    success: function (result) {
                        $("#email").val("");
                        if (result.code === 200) {
                            alert(result.data);
                        } else {
                            alert(result.msg);
                        }
                    },
                    //请求失败，包含具体的错误信息
                    error: function (e) {
                        console.log(e.status);
                        console.log(e.responseText);
                    }
                });
            }
        } else {
            let status = document.getElementById("status").getElementsByTagName("i")
            confirm_0.style.height = 0
            confirm_1.style.height = 0
            status[0].style.top = 0
            status[1].style.top = 35 + "px"
            onoff = !onoff
        }
    }

    //说明
    $(function () {
        const explanation = new mModal({
            content: "<p>一、系统分为两种功能</p>" +
                "<p>1. 退订（取消库存监控邮件通知）</p>" +
                "<p>2. 订阅（开启库存监控邮件通知）</p><br>" +
                "<p>二、系统仅为各位省去手动刷新页面问题，解放双手！</p>" +
                "<p>三、收到邮件通知后还需自己立即前往官网进行预约！</p><br>" +
                "<p>目前支持：iPhone12Pro、iPhone12</p>" +
                "<p>其它机型陆续增加中，敬请期待！！！</p><br>" +
                "<p style='color: coral;font-size: 10;'>注:如长时间没有收到邮件通知，请检查邮箱垃圾桶!</p>",
            confirm: function () {
                explanation.close();
            },
            cancel: function () {
                explanation.close();
            }
        });
        //说明按钮
        $("#explanation").on("click", function () {
            explanation.renderDom();
        });
        const reward = new mModal({
            content: "<p style='text-align: center;'>首先非常感谢您对本系统的支持！</p><br>" +
                "<p>本系统属个人空余时间进行开发与维护，尽最大能力满足各位需求！</p>" +
                "<p>如果您在使用后觉得对您有帮助，并愿意继续支持作者的开发维护！</p><br>" +
                "<p>打开微信扫一扫，随意打赏，再次感谢您对作者的支持。</p>" +
                "<div style='width:480px;height: 200px;display: table-cell;text-align: center;'><img style='width: 150px;height: 195px;' src=\"images/wxpay.png\" alt=\"微信”扫一扫“\"></div>",
            confirm: function () {
                reward.close();
            },
            cancel: function () {
                reward.close();
            }
        });
        //打赏按钮
        $("#reward").on("click", function () {
            reward.renderDom();
        });
    })
</script>
<script src="modal.js"></script>
</html>
